<!DOCTYPE HTML><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><? echo $title ?></title>
<? require("lib.php"); ?>
<link rel="stylesheet" href="css/jquery.datetimepicker.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
</head>
<body>
<div class="content-box">
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
<?
  switch ($do) {
    case "add": add(); break;
	case "update": update($info); break;
	case "delete": delete($id); break;
    default: show_info($info);
  }
	function show_box($row, $iseditmode, $isadd){
	global $id, $baseurl, $url, $title, $h, $cate, $lang, $option, $arrlang, $code_array, $lang;
	$arr_cate=$code_array['discount_type'];
?>
	<table width="99%" cellspacing="0" cellpadding="3" class="mbox">
      <tr class="th"><td class="thtitle" width="25%" align="right"><? echo $title ?></td><td>&nbsp;</td></tr>
      <tr><td class="l"><?=QUANTITY?></td><td><input type="text" value="" name="qty" class="g" /></td></tr>
      <tr><td class="l"><?=COUPON_TYPE?></td><td><? echo $h->select('discount_type', 0, $arr_cate, 'id', 'name_'.$lang, 'g'); ?></td></tr>
      <tr><td class="l"><?=VALUE?></td><td><input type="text" value="" name="discount_value" class="g" />
      <p class="gray">*<?=COUPON_TIP?></p>
      </td></tr>
      <tr><td class="l"><?=EXPIRE_DATE?></td><td><input type="text" value="" name="expire_date" class="g expire_date" /></td></tr>
      <tr><td class="l">&nbsp;</td><td><br><input <? if(!$iseditmode)echo "class='hide'";?> type="submit" value="&nbsp; <?=GENERATE?> &nbsp;">&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
    </table>
    <? }
	function show_boxes($result){ 
		global $page, $pages, $baseurl, $gee, $url, $lang, $customer,$cateid, $h, $code_array, $lang;
		echo $h->form($url.'.php', 0, ''); // 构建删除多项表单 form for deleting muti rows
		echo $h->hidden('action', 'deletes'); // 
		echo $h->hidden('page', $page); // 当前页面 current page
		echo $h->hidden('cateid', $cateid); // 当前分类 current category
		$str='<table width="99%" class="mlist"><tr>'; // 搜索
		$str.='<td>&nbsp;</td>';
		$str.='<td align="right"><a href="'.$url.'.php?do=add" class="blue">'.MESS_GENERATE.'</a> | <a href="'.$url.'.php?export=1" target="_blank" class="blue">'.ROOT_EXPORT_CSV.'</a></td>';
		$str.='</tr></table>';
		$str.= '<table width="99%" cellspacing="0" cellpadding="3" class="mlist" id="picbox"><tr class="th"><td width="48"><input type="checkbox" name="aller" class="check-all" /> '.ROOT_SELECT_ALL.'</td><td><strong>#</strong></td><td><strong>卡号</strong></td><td><strong>类型</strong></td><td><strong>数值</strong></td>
		<td><strong>过期时间</strong></td><td><strong>状态</strong></td>
		<td><strong>用户</strong></td>
		<td><strong>操作</strong></td>
		</tr>';
		$count=1;
		$arr_cate=$code_array['discount_type'];

    	foreach($result as $row)
		{
			$customer_id=$row['customer_id'];
			if($customer_id==0) $customer_name='-';
			else {
				$customer_array=$customer->get_row($customer_id);
				$customer_name=$customer_array['email'];
			}
			$status=$row['is_used'];
			$tem_status=$status?USED:'-';
			$tem_type=$arr_cate[$row['discount_type']]['name_'.$lang];

			$id=$row['id'];
      		$str.='<tr><td><input class="aller" type="checkbox" name="all[]" value="'.$id.'"" /></td><td>'.$id.'.</td><td>'.decode($row['code']).'</td><td>'.$tem_type.'</td>
      		<td>'.decode($row['discount_value']).'</td><td>'.decode($row['expire_date']).'</td><td>'.$tem_status.'</td><td>'.$customer_name.'</td>
      		';
			$str.='<td><a href="'.$url.'.php?do=delete&id='.$id.'" onClick="return delc();">'.ROOT_DELETE.'</a></td></tr>';
			$count++;
		}
		$str.="<tr><td colspan='8'> <input class='button' type='submit' value='".ROOT_DELETE_SELECTED."' onClick=\"javascript: return delc();\" /></td></tr></table>";		
		if($count==1) $str.= "<br>".ROOT_NO_DATA."!";
		echo $str;
		echo $h->former();
		$temurl=$url.'.php?page=';
		echo echo_page_raw($page, $pages, $temurl);
     } ?>
 <br class="clear" />
	</div>
         <br class="clear" />
</div>
<script type="text/javascript">
$(function(){
	var temlang='<?=$lang=="sc"?"ch":"en"?>';
	$('.expire_date').datetimepicker({
		format:'Y-m-d',lang:temlang,
		onShow:function(ct){
		this.setOptions({
			minDate:'<?=$tomorrow?>'
		})
	},
	timepicker:false
	});
});
</script>
</body>
</html>